<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <div v-if="crud.props.searchToggle">
        <!-- 搜索 -->
        <label class="el-form-item-label">载具编码（唯一标识）</label>
        <el-input v-model="query.containerCode" clearable placeholder="载具编码（唯一标识）" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <label class="el-form-item-label">载具类型(托盘/xx工装车/大料箱/小料箱)</label>
        <el-input v-model="query.containerType" clearable placeholder="载具类型(托盘/xx工装车/大料箱/小料箱)" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <label class="el-form-item-label">配送路径(xxx→xxx)</label>
        <el-input v-model="query.deliveryPath" clearable placeholder="配送路径(xxx→xxx)" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <label class="el-form-item-label">载具回收区(1:配管-管材 2:配管-板换 3:预装 4:电装)</label>
        <el-input v-model="query.recoveryArea" clearable placeholder="载具回收区(1:配管-管材 2:配管-板换 3:预装 4:电装)" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <label class="el-form-item-label">载具状态(1:正常 2:冻结 3:停用)</label>
        <el-input v-model="query.containerStatus" clearable placeholder="载具状态(1:正常 2:冻结 3:停用)" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <rrOperation :crud="crud" />
      </div>
      <!--如果想在工具栏加入更多按钮，可以使用插槽方式， slot = 'left' or 'right'-->
      <crudOperation :permission="permission" />
      <!--表单组件-->
      <el-dialog :close-on-click-modal="false" :before-close="crud.cancelCU" :visible.sync="crud.status.cu > 0" :title="crud.status.title" width="500px">
        <el-form ref="form" :model="form" :rules="rules" size="small" label-width="80px">
          <el-form-item label="载具编码（唯一标识）" prop="containerCode">
            <el-input v-model="form.containerCode" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="载具类型(托盘/xx工装车/大料箱/小料箱)">
            <el-input v-model="form.containerType" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="配送路径(xxx→xxx)">
            <el-input v-model="form.deliveryPath" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="尺寸(长) mm">
            <el-input v-model="form.dimensionLength" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="尺寸(宽) mm">
            <el-input v-model="form.dimensionWidth" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="重量 kg">
            <el-input v-model="form.weight" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="载具回收区(1:配管-管材 2:配管-板换 3:预装 4:电装)">
            <el-input v-model="form.recoveryArea" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="载具状态(1:正常 2:冻结 3:停用)">
            <el-input v-model="form.containerStatus" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="异常原因/备注">
            <el-input v-model="form.reason" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="创建时间" prop="createdAt">
            <el-input v-model="form.createdAt" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="更新时间" prop="updatedAt">
            <el-input v-model="form.updatedAt" style="width: 370px;" />
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="text" @click="crud.cancelCU">取消</el-button>
          <el-button :loading="crud.status.cu === 2" type="primary" @click="crud.submitCU">确认</el-button>
        </div>
      </el-dialog>
      <!--表格渲染-->
      <el-table ref="table" v-loading="crud.loading" :data="crud.data" size="small" style="width: 100%;" @selection-change="crud.selectionChangeHandler">
        <!-- <el-table-column type="selection" width="55" /> -->
        <el-table-column prop="containerCode" label="载具编码（唯一标识）" />
        <el-table-column prop="containerType" label="载具类型(托盘/xx工装车/大料箱/小料箱)" />
        <el-table-column prop="deliveryPath" label="配送路径(xxx→xxx)" />
        <el-table-column prop="dimensionLength" label="尺寸(长) mm" />
        <el-table-column prop="dimensionWidth" label="尺寸(宽) mm" />
        <el-table-column prop="weight" label="重量 kg" />
        <el-table-column prop="recoveryArea" label="载具回收区(1:配管-管材 2:配管-板换 3:预装 4:电装)" />
        <el-table-column prop="containerStatus" label="载具状态(1:正常 2:冻结 3:停用)" />
        <el-table-column prop="reason" label="异常原因/备注" />
        <el-table-column prop="createdAt" label="创建时间" />
        <el-table-column prop="updatedAt" label="更新时间" />
        <!-- <el-table-column v-if="checkPer(['admin','containerBasicInfo:edit','containerBasicInfo:del'])" label="操作" width="150px" align="center">
          <template slot-scope="scope">
            <udOperation
              :data="scope.row"
              :permission="permission"
            />
          </template>
        </el-table-column> -->
      </el-table>
      <!--分页组件-->
      <pagination />
    </div>
  </div>
</template>

<script>
import crudContainerBasicInfo from '@/api/work/containerBasicInfo'
import CRUD, { presenter, header, form, crud } from '@crud/crud'
import rrOperation from '@crud/RR.operation'
import crudOperation from '@crud/CRUD.operation'
// import udOperation from '@crud/UD.operation'
import pagination from '@crud/Pagination'

const defaultForm = { containerCode: null, containerType: null, deliveryPath: null, dimensionLength: null, dimensionWidth: null, weight: null, recoveryArea: null, containerStatus: null, reason: null, createdAt: null, updatedAt: null }
export default {
  name: 'ContainerBasicInfo',
  components: { pagination, crudOperation, rrOperation },
  mixins: [presenter(), header(), form(defaultForm), crud()],
  cruds() {
    return CRUD({ title: 'container_basic_info', url: 'api/containerBasicInfo', idField: 'id', sort: 'id,desc', crudMethod: { ...crudContainerBasicInfo },
      optShow: {
        add: false,
        edit: false,
        download: true,
        del: false,
        reset: true
      }
    })
  },
  data() {
    return {
      permission: {
        add: ['admin', 'containerBasicInfo:add'],
        edit: ['admin', 'containerBasicInfo:edit'],
        del: ['admin', 'containerBasicInfo:del']
      },
      rules: {
        containerCode: [
          { required: true, message: '载具编码（唯一标识）不能为空', trigger: 'blur' }
        ],
        createdAt: [
          { required: true, message: '创建时间不能为空', trigger: 'blur' }
        ],
        updatedAt: [
          { required: true, message: '更新时间不能为空', trigger: 'blur' }
        ]
      },
      queryTypeOptions: [
        { key: 'containerCode', display_name: '载具编码（唯一标识）' },
        { key: 'containerType', display_name: '载具类型(托盘/xx工装车/大料箱/小料箱)' },
        { key: 'deliveryPath', display_name: '配送路径(xxx→xxx)' },
        { key: 'recoveryArea', display_name: '载具回收区(1:配管-管材 2:配管-板换 3:预装 4:电装)' },
        { key: 'containerStatus', display_name: '载具状态(1:正常 2:冻结 3:停用)' }
      ]
    }
  },
  methods: {
    // 钩子：在获取表格数据之前执行，false 则代表不获取数据
    [CRUD.HOOK.beforeRefresh]() {
      return true
    }
  }
}
</script>

<style scoped>

</style>
